/**
 * NOTICE OF LICENSE
 *
 * This source file is subject to the  Academic Free License (AFL 3.0)
 * that is available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to support@zprofess.com so we can send you a copy immediately.
 *
 * @category   	Prestashop module
 * @package		Review & Rating Synthesis
 * @version 	1.0.2
 * @author 		Rukan <rukanhitokiri@zprofess.com>
 * @copyright   Copyright (c) 2012 ZPROFESS. (http://www.zprofess.com)
 * @license    	http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 * @by 			xuanhoapro
 */
$(document).ready(function(){
	var body = $('body').attr('id');
	// add alias input when create account
	if (body == 'authentication' || body == 'order-opc'){
		$("#customer_lastname").parent().after('<p class="required text"><label for="alias_custommer">Alias Custommer</label><input type="text" class="text" id="alias_custommer" name="alias_custommer"><sup></sup></p>');
	}
	// add alias input & option when edit account
	if (body == 'identity'){
		$.ajax({
			type: 'GET',
			url: baseDir + 'modules/reviewratingsynthesis/ZEditAlias-ajax.php',
			async: true,
			cache: false,
			dataType: 'html',
			success: function(data)
			{
				$("#lastname").parent().after(data);
			}
		});
		
		/*
		$('.std').submit(function(){
			alias = $("#alias_custommer").val();
			alias_active = $('input:radio[name=alias_active]:checked').val();
			$.ajax({
				type: 'GET',
				async: true,
				cache: false,
				url: baseDir + 'modules/reviewratingsynthesis/ZUpdateAlias-ajax.php', 
				data:"alias_custommer="+alias+"&alias_active="+alias_active,
				success: function(data) {
				}
			});
			return true;
		});
		*/
		$('.std').submit(function(){
			var alias = $.trim($('#alias_custommer').val ());
			var select = $('input:radio[name=alias_active]:checked').val ();

			if (select == 2 && alias=='') {
				$('.error').remove();
				$("h1").after('<div class="error"><p>There is 1 error :</p><ol><li>You selected "Review name display" is "Alias name" then must put in field "Alias Custommer" </li></ol></div>');
				window.scrollTo(10,10)
				return false;
			}
			else { 
				return true;
			}
		});
	}
});